<?php

class Application_Model_DbTable_Empresas extends Zend_Db_Table_Abstract
{

    protected $_name = 'empresas';
	
	public function getEmpresas() {
		$select  = $this->_db->select()
			->from($this->_name);

		$result = $this->getAdapter()->fetchAll($select);

		return $result;
	}
	
	public function getEmpresasList() {
		$select  = $this->_db->select()
			->from($this->_name,array('key' => 'id','value' => 'nombre'));

		$result = $this->getAdapter()->fetchAll($select);

		return $result;
	}

	public function getEmpresasFromId($idEmpresa) {
		$select  = $this->_db->select()
			->from($this->_name)->where('id = ?', $idEmpresa);

		$result = $this->getAdapter()->fetchAll($select);

		return $result;
	}
	
	public function getIdEmpresaFromName($nombre) {
		$select  = $this->_db->select()
			->from($this->_name)->where('usuario = ?', $nombre);

		$result = $this->getAdapter()->fetchAll($select);

		return $result;
	}

	public function countEmpresas() {
		$select  = $this->_db->select('')
			->from($this->_name, array('total' => 'COUNT(*)'));

		$result = $this->getAdapter()->fetchAll($select);

		return $result[0]['total'];
	}
}

